import { Scene } from "phaser";

export class Menu extends Scene {
    constructor() {
        super("Menu");
    }
    create() {
        // 添加背景音乐和雪花背景
        this.sound.play("music", { loop: true, delay: 2 });
        this.add.shader("snow", 512, 384, 1024, 768);

        // 3个球和标题
        let ball1 = this.add.image(-64, 300, "sprites", "snowball1");
        let ball2 = this.add.image(1088, 360, "sprites", "snowball1");
        let ball3 = this.add.image(-64, 320, "sprites", "snowball1");
        let title = this.add.image(1700, 384, "title");

        this.tweens.add({
            targets: ball1,
            x: 1088,
            y: 360,
            ease: "cubic.out",
            duration: 600,
            onStart: () => {
                this.sound.play("throw");
            },
        });
        this.tweens.add({
            targets: ball2,
            x: -64,
            y: 280,
            ease: "cubic.out",
            delay: 700,
            duration: 600,
            onStart: () => {
                this.sound.play("throw");
            },
        });
        this.tweens.add({
            targets: ball3,
            x: 1088,
            y: 380,
            ease: "cubic.out",
            delay: 1200,
            duration: 600,
            onStart: () => {
                this.sound.play("throw");
            },
        });
        this.tweens.add({
            targets: title,
            x: 512,
            ease: "back.out",
            delay: 1800,
            duration: 600,
            onStart: () => {
                this.sound.play("throw");
            },
        });

        // 空格键或任意点击，打开Main场景
        this.input.keyboard.once("keydown-SPACE", () => this.scene.start("Main"), this);
        this.input.once("pointerdown", () => this.scene.start("Main"), this);
    }
}
